# -*- coding: UTF-8 -*-
# Author: Damon(wuud1)
# CreateDate:
# Message:

import requests
from lxml import etree


url = "https://catalogue.bosch-trading.com.cn/api/verification"
pid = "LR001247"
post_data = {
    'refer': "https%3A%2F%2Fcatalogue.bosch-trading.com.cn%2Fcn%2Fsearch%2F1%3Fq%3D{}".format(pid),
    'code': 'mqmf59'
}
headers = {
    "Host": "catalogue.bosch-trading.com.cn",
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
    "Referer": "https://catalogue.bosch-trading.com.cn/cn/verification?refer=https%3A%2F%2Fcatalogue.bosch-trading.com.cn%2Fcn%2Fsearch%2F1%3Fq%3D{}".format(pid),
    "X-Requested-With": "XMLHttpRequest"
}
cookies = {
    "UM_distinctid": "1648d9f06cb150-0719ad59bd385b-16386952-13c680-1648d9f06cc225",
    "CNZZDATA1257733696": "419851453-1531383363-%7C1532418189",
    "ci_session": "a45g0d1ng8vh02647kjacfsmusi7mefu"
}

location = "https://catalogue.bosch-trading.com.cn/cn/verification?refer=https%3A%2F%2Fcatalogue.bosch-trading.com.cn%2Fcn%2Fsearch%2F1%3Fq%3D{}".format(pid)

res = requests.get(url=location, headers=headers, cookies=cookies)
ci_session = res.cookies.get_dict()
ci_session = ci_session.get('ci_session', "a45g0d1ng8vh02647kjacfsmusi7mefu")
print ci_session
cookies['ci_session'] = ci_session



res = requests.post(url=url,data=post_data,headers=headers,cookies=cookies)
with open("./test.html", 'w') as f:
    f.write(res.content.decode("utf8"))
    print res.cookies.get_dict()

